<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.SMSUtil" %>
<%@ include file="/public/header.jsp"%>


<html>
	<head>
		<title>我的消息管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$('#type_id').combobox({  
        		url:'<%=contextPath %>/springMVC/sms/getSMSModule',  
       			valueField:'id',  
        		textField:'value',
        		onChange:function(){
        			doSearch();
        		}
   			});  
			$("#table").datagrid({
				title:"我的消息管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/sms/listPageSMS',
				queryParams:{is_read:"<%=request.getParameter("is_read")%>"},                                                
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
	                {field:'ck',checkbox:true},
				    {title:'编号',field:'id',hidden:true}
				]],
				columns:[[
					{title:'消息创建者',field:'truename',width:100,align:'center'},
					{title:'消息类别',field:'sms_module',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var module="";
						if(value=='<%=SMSUtil.SMS_FLOW%>'){
							module="<%=SMSUtil.getSMSModuleNameByKey(SMSUtil.SMS_FLOW)%>";
						}
						if(value=='<%=SMSUtil.SMS_GD_SECURITY%>'){
							module="<%=SMSUtil.getSMSModuleNameByKey(SMSUtil.SMS_GD_SECURITY)%>";
						}
						if(value=='<%=SMSUtil.SMS_GD_FINISH_ALARM%>'){
							module="<%=SMSUtil.getSMSModuleNameByKey(SMSUtil.SMS_GD_FINISH_ALARM)%>";
						}
						if(value=='<%=SMSUtil.SMS_XM_INVOICE_ALARM%>'){
							module="<%=SMSUtil.getSMSModuleNameByKey(SMSUtil.SMS_XM_INVOICE_ALARM)%>";
						}
						if(value=='<%=SMSUtil.SMS_GD_DESCRIPTION%>'){
							module="<%=SMSUtil.getSMSModuleNameByKey(SMSUtil.SMS_GD_DESCRIPTION)%>";
						}
						return module;
						}
					},
					{title:'消息主题',field:'sms_title',width:100,align:'center'},
					{title:'消息创建时间',field:'create_time',width:100,align:'center'},
					{title:'消息已读时间',field:'read_time',width:100,align:'center'},
					{title:'是否已读',field:'is_read',width:100,align:'center',formatter:function(value,rowDate,rowIndex){
						var rvalue="";
						if(value==1){
							rvalue="已读";
						}else {
							rvalue="未读";
						}
						return rvalue;
						}
					},


					{title:'查看详情',field:'sms_link',width:50,align:'center',formatter:function(value,rowData,rowIndex){
						return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看详情' onclick=\"javascript:goLink('"+rowData.id+"','"+ value +"');\">";
			
	
					}}
				]],
				
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				toolbar:'#tb',
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
			
		});
          
    
		function rtCallBack(){
			$('#table').datagrid('reload');
		}

		function doSearch(){
			var searchValue = $('#searchValue').val();
			var type_id = $('#type_id').combobox('getValue');
			var is_read= $('#is_read').val();
			$('#table').datagrid('load',{
				sms_title:searchValue,
				sms_module:type_id,
				is_read:is_read
				});
		}
		function goLink(id,linkurl){	
			updateRead(id);
			if(linkurl==null || linkurl=="" || linkurl=="undefined"){
			openDialogResize("<%=contextPath %>/springViews/myWorks/viewSms.jsp?id="+id,1000, 800);
			}
			else{
			openDialogResize("<%=contextPath %>/"+linkurl,1000, 800);	
			}
		}
		function deleteRows(){
			var rows=$('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				$.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/sms/deleteSMS",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								$.messager.alert('提示：',rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function updateReadRows(){
			var rows=$('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				$.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			$.messager.confirm('确认','您确认置为已读？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/sms/updateSMSRead",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								$.messager.alert('提示：',rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function updateRead(id){

			var rows=$('#table').datagrid('getSelections');
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/sms/updateSMSRead",
						data:"ids="+id,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
						}
			});
		}
	</script>
	<body>
		<div id="smsManage" class="easyui-layout" data-options="fit:true">
			<div region="center"  style="padding:5px;">
			    	<div id="table" data-options="fit:true"></div>
			    	<div id="tb" style="padding:3px;height:auto">
						<div style="float:left;">
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteRows();">删除</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="updateReadRows();">标记已读</a>
						</div>
<div align="right">
     消息：<select id="is_read" class="" name="is_read" style="width:200px;" onchange="doSearch()">   
     <option value="">全部</option> 
    <option value="0" selected>未读</option>   
    <option value="1">已读</option>   
</select>  
	消息类型：<select id="type_id" name="type_id" style="width:200px;" onchange="doSearch()"></select>  


							查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="消息名称"/>&nbsp;&nbsp;
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
						</div>
					</div>
		    </div>
		</div>
	</body>
</html>
